package com.example.demo.kafka;

import com.alibaba.fastjson.JSON;
import com.example.demo.redis.RedisClient;
import com.example.demo.util.LogUtils;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

/**
 * @author zhangxinju@hellobike.com
 * @date 2019-08-23 09:40
 **/
@Component
public class KafkaConsumer {


    private final RedisClient redisClient;

    @Autowired
    public KafkaConsumer(RedisClient redisClient) {
        this.redisClient = redisClient;
    }

    @KafkaListener(topics = "xinju")
    public void listen(ConsumerRecord<?,?> consumerRecord){
        Object value = consumerRecord.value();
        LogUtils.COMMON.info("listen message from producer:{}", JSON.toJSONString(value));
    }
}
